<template>
  <div>
    <redact
      :from-data="fromData"
      @submit="updataApplication"
      :categoryList="categoryList"
    />
  </div>
</template>
<script>
import redact from "./components/template.vue";
import {
  applicationInfo,
  updataApplication,
} from "@/api/system/application_management";
import { categoryQueryList } from "@/api/system/classified_management";
export default {
  name: "updateApplication",
  components: {
    redact,
  },
  data() {
    return {
      id: undefined,
      fromData: {
        categoryId: undefined,
        applicationName: undefined,
        sceneDesc: undefined,
        contactName: undefined,
        deleteFlag: 1,
        phoneNum: undefined,
        address: undefined,
      },
      categoryList: [],
      isClick: 1,
    };
  },
  mounted() {
    this.id = this.$route.query.id;
    this.applicationInfo();
    this.categoryQueryList();
  },
  methods: {
    // 查询应用id的信息
    applicationInfo() {
      applicationInfo({ applicationId: this.id }).then((response) => {
        this.fromData = response.data;
      });
    },
    // 查询所有分类
    categoryQueryList() {
      this.loading = true;
      categoryQueryList(this.addDateRange({ pageNum: 1, pageSize: 1000 })).then(
        (response) => {
          this.categoryList = response.data.list;
        }
      );
    },
    updataApplication() {
      if (this.isClick === 1) {
        this.isClick = 0;
        updataApplication(this.fromData)
          .then((response) => {
            this.msgSuccess("编辑成功");
            // 调用全局挂载的方法
            this.$store.dispatch("tagsView/delView", this.$route);
            // 返回上一步路由
            this.$router.go(-1);
            // this.$store.dispatch('settings/changeRefresh', true)
          })
          .catch((res) => {
            this.isClick = 1;
          });
      }
    },
  },
};
</script>
